//
//  DailyWeatherView.m
//  NewBiuWeather
//
//  Created by 楼楚 on 16/4/9.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "DailyWeatherView.h"
#import "WeatherNumberMeaningTransform.h"

@interface DailyWeatherView () <UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UILabel *cityLabel;
@property (nonatomic,strong) UILabel *maxMinLabel;
@property (nonatomic,strong) UILabel *currentLabel;
@property (nonatomic,strong) UILabel *weatherIconLabel;
@property (nonatomic,strong) UILabel *weatherDescriLabel;
@property (nonatomic,strong) UILabel *windDirLabel;

@end

@implementation DailyWeatherView
-(void)buildView{
    self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.separatorColor = [UIColor colorWithWhite:1 alpha:0.2];
    self.tableView.pagingEnabled = YES;
    [self addSubview:self.tableView];
    
    self.currentLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, Height-150, Width - 40, 110)];
    self.currentLabel.backgroundColor = [UIColor clearColor];
    self.currentLabel.textColor = [UIColor whiteColor];
    self.currentLabel.font = [UIFont systemFontOfSize:120];
    
    self.maxMinLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, Height - 40, Width - 40, 40)];
    self.maxMinLabel.backgroundColor = [UIColor clearColor];
    self.maxMinLabel.textColor = [UIColor whiteColor];
    self.maxMinLabel.font = [UIFont systemFontOfSize:28];
    
    self.cityLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, Width, 30)];
    self.cityLabel.backgroundColor = [UIColor clearColor];
    self.cityLabel.textColor = [UIColor whiteColor];
    self.cityLabel.font = [UIFont systemFontOfSize:18];
    self.cityLabel.textAlignment = NSTextAlignmentCenter;
    
    self.weatherDescriLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, Height - 180, 30, 30)];
    self.weatherDescriLabel.backgroundColor = [UIColor clearColor];
    self.weatherDescriLabel.textColor = [UIColor whiteColor];
     self.weatherDescriLabel.font = [UIFont systemFontOfSize:18];
    
    self.weatherIconLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, Height - 180, 50, 30)];
    self.weatherIconLabel.backgroundColor = [UIColor clearColor];
    self.weatherIconLabel.textColor = [UIColor whiteColor];
    self.weatherIconLabel.font = [UIFont fontWithName:WEATHER_TIME size:18];
    
    [self.tableView addSubview:self.currentLabel];
    [self.tableView addSubview:self.maxMinLabel];
    [self.tableView addSubview:self.cityLabel];
    [self.tableView addSubview:self.weatherDescriLabel];
    [self.tableView addSubview:self.weatherIconLabel];
    
}
- (void)show{
    self.cityLabel.text =self.cityName;
    self.currentLabel.text = self.today.temp;
    self.maxMinLabel.text = [NSString stringWithFormat:@"%@°/%@°",self.maxminInfo.maxTmp,self.maxminInfo.minTmp];
    self.weatherDescriLabel.text = self.today.weatherTxt;
    self.weatherIconLabel.text = [WeatherNumberMeaningTransform fontTextWeatherNumber:self.today.weatherCode];
    
}
- (void)hide{
    self.currentLabel.text = @"";
    self.maxMinLabel.text = @"";
    self.cityLabel.text = @"";
    self.weatherIconLabel.text = @"";
    self.weatherDescriLabel.text = @"";
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (scrollView.contentOffset.y >= 60.f){
        if (_delegate&&[_delegate respondsToSelector:@selector(pullUpEvent)]) {
            [_delegate pullUpEvent];
            
        }
        
    }
    if (scrollView.contentOffset.y <= -60.f) {
        if (_delegate && [_delegate respondsToSelector:@selector(pullDownToRefreshData)]) {
            
            [_delegate pullDownToRefreshData];
        }
        
    }
}




@end
